<template>
  <div>
    <div class="analysisGeneration-content2">
      <span class="s">邮箱数据解析</span>
      <el-input v-model="mailboxData" placeholder="请输入邮箱解析数据" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" clearable class="mr-12 "></el-input>
      <el-button type="primary" @click="startParsingClick">开始数据解析</el-button>
    </div>
    <ul class="CiscoAnyco1">
      <li>
        <span>邮箱</span>
        <el-input v-model="mailbox" placeholder="请输入邮箱" disabled></el-input>
        <el-button :type="butType['mailbox']" @click="copyLink(mailbox,'mailbox')" class="tag">复制</el-button>
      </li>
      <li>
        <span>密码</span>
        <el-input v-model="password" placeholder="请输入密码" disabled></el-input>
        <el-button :type="butType['password']" @click="copyLink(password,'password')" class="tag">复制</el-button>
      </li>
      <li>
        <span>辅助邮箱</span>
        <el-input v-model="secondaryMailbox" placeholder="请输入邮箱" disabled></el-input>
        <el-button :type="butType['secondaryMailbox']" @click="copyLink(secondaryMailbox,'secondaryMailbox')" class="tag">复制</el-button>
      </li>
      <li>
        <span>新密码</span>
        <el-input v-model="newPasswords" placeholder="请输入邮箱" disabled></el-input>
        <el-button :type="butType['newPasswords']" @click="copyLink(newPasswords,'newPasswords')" class="tag">复制</el-button>
      </li>
    </ul>
    <div class="analysisGeneration-content3">
      <el-button type="danger" size="medium" @click="initializationClcik">初始化</el-button>
    </div>
  </div>
</template>

<script>
import Clipboard from 'clipboard'
export default {
  components: {},
  props: [],
  data() {
    return {
      mailboxData:'oquendor.ueben@gmail.com|bosssavCFFgB|q04902sw6c653@tmmails.ws',//邮箱地址 | 分割
      mailbox:'',//邮箱
      password:'',//密码
      secondaryMailbox:'',//辅助邮箱
      newPasswords:'',//新密码
      //复制按钮状态
      butType:{
        mailbox:'',//邮箱
        password:'',//密码
        secondaryMailbox:'',//辅助邮箱
        newPasswords:'',//新密码
      },
    };
  },
  mounted() {
  },
  methods: {
    //开始邮箱解析
    startParsingClick(){
      let a=this.mailboxData.split('|');
      this.mailbox=a[0];
      this.password=a[1];
      this.secondaryMailbox=a[2];
      this.newPasswords=this.generatePassword(10);
    },
    //初始化
    initializationClcik() {
      this.$confirm('此操作将刷新页面初始化?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.go(0);
      }).catch(() => {
        this.$message.info('已取消初始化');
      });
    },
    //复制
    copyLink(data, key) {
      let clipboard = new Clipboard('.tag', {
        text: function () {
          return data
        }
      })
      clipboard.on('success', e => {
        console.log(e);
        this.butType[key]= 'success';
        this.$message({message: '复制成功', showClose: true, type: 'success'})
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', e => {
        console.log(e);
        this.$message({message: '复制失败,', showClose: true, type: 'error'})
        clipboard.destroy()
      })
    },
    // 随机密码生成
    generatePassword(length) {
      let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
      let password = '';
      for (let i = 0; i < length; i++) {
        let randomNumber = Math.floor(Math.random() * chars.length);
        password += chars.substring(randomNumber, randomNumber + 1);
      }
      return password;
    }
  },
};
</script>

<style lang="scss" scoped>
.CiscoAnyco1 {
  margin-bottom: 10px;

  li {
    @include flex();
    margin-bottom: 10px;
    .el-input{
      width: 350px;
      flex:0 0 auto;
    }
    span {
      width: 80px;
      flex: 0 0 auto;
      text-align: center;
    }

    .el-button--small {
      margin-left: 8px;
    }
  }
}

</style>
